package com.zhiyou.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.zhiyou.dao.HouseMapper;
import com.zhiyou.entity.House;
import com.zhiyou.entity.Msg;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/House")
public class HouseControlle {
    @Autowired
    HouseMapper houseMapper;

    @RequestMapping("/getAll")
    public String getAllHouse(@RequestParam(value = "pn",defaultValue = "1")Integer pn,Model model){
        PageHelper.startPage(pn,5);
        List<House> houses = houseMapper.selectAll();
        PageInfo pageInfo = new PageInfo(houses,5);
        Msg pageInfo1 = Msg.success().add("pageInfo", pageInfo);
        model.addAttribute("pageInfo",pageInfo);

        return "House/HouseList";
    }

//    @RequestMapping("/getAll")
////    @ResponseBody
//    public Msg getHouseWithJson(@RequestParam(value = "pn",defaultValue = "1") Integer pn){
//        PageHelper.startPage(pn,5);
//        List<House> houses = houseMapper.selectAll();
//        PageInfo pageInfo = new PageInfo(houses,5);
//        return Msg.success().add("pageInfo",pageInfo);
//    }

//    @RequestMapping("HouseList")
//    public String HouseList(@RequestParam(value = "pn",defaultValue = "1")Integer pn,Model model){
//        PageHelper.startPage(pn,5);
//        List<House> houses = houseMapper.selectAll();
//        PageInfo pageInfo = new PageInfo(houses,5);
//        Msg pageInfo1 = Msg.success().add("pageInfo", pageInfo);
//        model.addAttribute("House",pageInfo);
//
//        return "House/HouseList";
//    }



}
